from django.db import models

# Create your models here.
class UserInfo(models.Model):
    """
    用户信息表
    """
    username = models.CharField(max_length=32,unique=True,verbose_name="用户名")
    password = models.CharField(max_length=64)
    create_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.username

    class Meta:
        verbose_name = "用户信息"
        verbose_name_plural = verbose_name
        db_table = 'UserInfo'

class Remen(models.Model):
    """
    热门电影表
    """
    rate = models.FloatField(max_length=255,verbose_name="豆瓣评分")
    title = models.CharField(max_length=255,verbose_name="电影名称")
    url = models.CharField(max_length=255,verbose_name="电影介绍详细地址")
    src = models.CharField(max_length=255,verbose_name="电影图片地址")
    time = models.DateTimeField(auto_now=True,verbose_name="数据更新时间")

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "热门电影表"
        verbose_name_plural = verbose_name
        db_table = 'Remen'


class New(models.Model):
    """
    最新电影表
    """
    rate = models.FloatField(max_length=255,verbose_name="豆瓣评分")
    title = models.CharField(max_length=255,verbose_name="电影名称")
    url = models.CharField(max_length=255,verbose_name="电影介绍详细地址")
    src = models.CharField(max_length=255,verbose_name="电影图片地址")
    time = models.DateTimeField(auto_now=True,verbose_name="数据更新时间")

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "最新电影表"
        verbose_name_plural = verbose_name
        db_table = 'New'



class Jingdian(models.Model):
    """
    经典电影表
    """
    rate = models.FloatField(max_length=255,verbose_name="豆瓣评分")
    title = models.CharField(max_length=255,verbose_name="电影名称")
    url = models.CharField(max_length=255,verbose_name="电影介绍详细地址")
    src = models.CharField(max_length=255,verbose_name="电影图片地址")
    time = models.DateTimeField(auto_now=True,verbose_name="数据更新时间")

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "经典电影表"
        verbose_name_plural = verbose_name
        db_table = 'Jingdian'


class DoubanTop(models.Model):
    """
    豆瓣高分电影表
    """
    rate = models.FloatField(max_length=255,verbose_name="豆瓣评分")
    title = models.CharField(max_length=255,verbose_name="电影名称")
    url = models.CharField(max_length=255,verbose_name="电影介绍详细地址")
    src = models.CharField(max_length=255,verbose_name="电影图片地址")
    time = models.DateTimeField(auto_now=True,verbose_name="数据更新时间")

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "豆瓣高分电影表"
        verbose_name_plural = verbose_name
        db_table = 'DoubanTop'


class Comment(models.Model):
    """
    最新影评
    """
    comment_title = models.CharField(max_length=255,verbose_name="评论标题")
    src = models.CharField(max_length=255,verbose_name="图片地址")
    user = models.CharField(max_length=255,verbose_name="评价用户")
    text =  models.CharField(max_length=640,verbose_name="评价内容")
    time =  models.CharField(max_length=255,verbose_name="评价时间")
    url = models.CharField(max_length=255,verbose_name="详情地址")

    def __str__(self):
        return self.user

    class Meta:
        verbose_name = "最新影评"
        verbose_name_plural = verbose_name
        db_table = 'Comment'




class History(models.Model):

    rate = models.FloatField(max_length=255,verbose_name="豆瓣评分")
    title = models.CharField(max_length=255,verbose_name="电影名称")
    url = models.CharField(max_length=255,verbose_name="电影介绍详细地址")
    src = models.CharField(max_length=255,verbose_name="电影图片地址")
    time = models.DateTimeField(auto_now=True,verbose_name="数据更新时间")

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "所有电影"
        verbose_name_plural = verbose_name
        db_table = 'All'



class Look(models.Model):

    user = models.ForeignKey(verbose_name="用户", to="UserInfo",on_delete=models.CASCADE)
    history = models.ForeignKey(verbose_name="电影", to="History",on_delete=models.CASCADE)

    def __str__(self):
        return self.user.username

    class Meta:
        verbose_name = "浏览电影"
        verbose_name_plural = verbose_name
        db_table = 'Look'
